import java.util.Objects;
import java.util.Scanner;

/**
 * @version 1.0
 * @program: JavaStage3Project
 * @description: 测试用主函数
 * @author: Kishan Liu
 * @create: 2021-12-11 10:01
 **/
public class TestMain {
    public static void main(String[] args) {
        mainMenu();
    }


    public static void mainMenu(){
        SerialNumber number=new SerialNumber();
        welcomeMenu();
        for (;;){
            int model=modelMenu();
            if (model==1){
                do {
                    number.setParameter(setParameter());
                    number.setNumber(number.getParameter());
                    System.out.println(number.getNumber());
                }while (askCirculation());
            }else if (model==2){
               do {
                   number.setNumber();
                   System.out.println(number.getNumber());

               }while (askCirculation());
            }else {
                byeMenu();
                break;
            }
        }
    }

    private static void welcomeMenu(){
        System.out.println("**********欢迎使用流水号生成器***********");
        System.out.println("本程序可以帮您按照指定格式一键生成流水号！");
    }

    private static void byeMenu(){
        System.out.println("期待您的下次使用！再见~");
    }

    private static int modelMenu(){
        int select;
        System.out.println("请选择您想要生成流水号的模式：");
        System.out.println("1.字母加固定长度数字。");
        System.out.println("2.时间加固定长度数字。");
        System.out.println("3.退出。");
        for (;;) {
            Scanner in = new Scanner(System.in);
            if (in.hasNextInt()){
                select=in.nextInt();
                if (select==1){
                    System.out.println("选择成功！为字母模式！");
                    return select;
                }else if (select==2){
                    System.out.println("选择成功！为时间模式！");
                    return select;
                }else if (select==3){
                    return select;
                }else
                    System.out.println("请输入1-3!");
            }else
                System.out.println("请输入模式编号(数字)！");
        }
    }


    private static String setParameter (){
        String parameter;
        String x ;
        do {
            System.out.println("是否预设流水号参数？(y/n)(默认为M)");
            Scanner in = new Scanner(System.in);
            x= in.next();
        } while (!Objects.equals(x, "y") && !Objects.equals(x, "Y") && !Objects.equals(x, "n") && !Objects.equals(x, "N"));
        if (Objects.equals(x, "y") || Objects.equals(x, "Y")){
            System.out.println("请输入您需要的参数：");
            Scanner in =new Scanner(System.in);
            parameter = in.next();
        }
        else
            parameter="M";
        return parameter;
    }

    private static boolean askCirculation (){
        String x;
        do {
            System.out.println("是否继续生成当前格式的流水号？(y/n)");
            Scanner in = new Scanner(System.in);
            x= in.next();
        } while (!Objects.equals(x, "y") && !Objects.equals(x, "Y") && !Objects.equals(x, "n") && !Objects.equals(x, "N"));
        return Objects.equals(x, "y") || Objects.equals(x, "Y");
    }
}

